<template>
  <el-container style="height:100%;width:100%">
    <el-header>
      <div style="margin: 20px">
        <img src="@/assets/aihui.png" alt="">
      </div>
    </el-header>
    <el-main style="padding: 0;">
      <div class="login-container">
        <img class="pattern" src="@/assets/pattern.png" alt="">
        <img class="title" src="@/assets/title.png" alt="">
        <el-form ref="loginForm" :model="loginForm" class="login-form" auto-complete="on" label-position="left">
          <!-- <h3 class="title">门诊辅助系统</h3> -->
          <span class="label">用户名</span>
          <el-form-item prop="loginUser">
            <span class="svg-container">
              <svg-icon icon-class="user" />
            </span>
            <el-input v-model="loginForm.loginUser" name="loginUser" type="text" auto-complete="on" placeholder="用户名" />
          </el-form-item>
          <span class="label">密码</span>
          <el-form-item prop="password">
            <span class="svg-container">
              <svg-icon icon-class="password" />
            </span>
            <el-input
              :type="pwdType"
              v-model="loginForm.password"
              name="password"
              auto-complete="on"
              placeholder="密码"
              @keyup.enter.native="handleLogin" />
            <span class="show-pwd" @click="showPwd">
              <svg-icon icon-class="eye" />
            </span>
          </el-form-item>
          <el-form-item>
            <el-button :loading="loading" type="primary" style="width:100%;" @click.native.prevent="handleLogin">
              登录
            </el-button>
          </el-form-item>
          <!-- <div class="tips">
            <span style="margin-right:20px;">loginUser: admin</span>
            <span> password: admin</span>
          </div> -->
        </el-form>
      </div>
    </el-main>
    <el-footer style="height:20px;text-align:center">
      <span style="color: white">技术支持 ©杭州爱惠信息技术有限公司  浙ICP备15003389号-3</span>
    </el-footer>
  </el-container>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        loginUser: '666001',
        password: '0'
      },
      loading: false,
      pwdType: 'password',
      redirect: undefined
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  methods: {
    showPwd() {
      if (this.pwdType === 'password') {
        this.pwdType = ''
      } else {
        this.pwdType = 'password'
      }
    },
    handleLogin() {
      // this.$router.push('/patientInfo')
      if (this.loginForm.loginUser == 'admin') {
        alert('不支持后端管理员登陆')
        return false
      }
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('Login', this.loginForm).then(() => {
            console.log('登录执行完毕')
            this.$router.push({ path: this.redirect || '/' })
            // this.$store.dispatch('GetMenus').then(() => {
            //   this.loading = false
            // })
          }).catch(() => {
            this.loading = false
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
$bg:#2d3a4b;
$light_gray:#eee;
$dark_gray:#889aa4;
/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    width: 85%;
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $dark_gray;
      &:-webkit-autofill {
        -webkit-box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: #fff !important;
      }
    }
  }
  .el-form-item {
    border: 1px solid #d5d5d5;
    background: white;
    border-radius: 5px;
    color: #454545;
  }
}

</style>

<style rel="stylesheet/scss" lang="scss" scoped>
.title {
  z-index: 100; /* ?? */
  // display: block;
  // margin: 200px auto;
  position: absolute;
  left: 550px;
  top: 200px;
}
.pattern {
  position: absolute;
}
.el-container {
  background-image: url("../../assets/background.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  -moz-background-size:100% 100%;
}
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;
.login-container {
  position: fixed;
  height: 100%;
  width: 100%;
  // background-color: $bg;
  .login-form {
    z-index: 100;
    background: white;
    border-radius: 5px;
    position: absolute;
    // left: 0;
    right: 100px;
    width: 420px;
    max-width: 100%;
    padding: 35px 35px 15px 35px;
    margin: 120px auto;
    .label {
      display: block;
      color: #666666;
      margin-bottom: 10px;
    }
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }
  .title {
    font-size: 26px;
    font-weight: 400;
    color: $light_gray;
    margin: 0px auto 40px auto;
    text-align: center;
    font-weight: bold;
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
